﻿using QFramework;
using UnityEngine;

namespace ProjectSurvivor
{
    public class Dissolve : MonoBehaviour
    {
        public Material Material;
        private static readonly int Color = Shader.PropertyToID( "_Color");
        private static readonly int Fade = Shader.PropertyToID( "_Fade");
        private static readonly int MainText = Shader.PropertyToID( "_MainText");
        public Color DissolveColor;
        public Texture Texture;
        private void Start()
        {
            var material = Instantiate(Material);
            GetComponent<SpriteRenderer>().material = material;
            material.SetColor(Color, DissolveColor);
            material.SetTexture(MainText,Texture);
            ActionKit.Lerp(1, 0, 0.5f, fade =>
            {
                material.SetFloat(Fade, fade);
                this.LocalScale(1 + (1 - fade) * 0.5f);
            })
                .Start(this, () =>
                {
                    Destroy(material);
                    this.DestroyGameObjGracefully();
                });
        }
    }
}
